home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / OBJ1_2.ZIP;1 / C_INFO.PRG < prev    next >
Encoding:
Text File  |  1993-01-21  |  8.3 KB  |  252 lines

  1. //*****************************************************************************
  2. // C_Info.prg
  3. // Information (memo) class for OBJECT v2.03
  4. // Copyright (c) 1991, JHK, JHK-Software, Piestany
  5. // Please compile with: /N/M/W/A
  6. //-----------------------------------------------------------------------------
  7.  
  8. #include "InKey.ch"
  9. #include "Object.ch"
  10. #include "SetCurs.ch"
  11. #include "MemoEdit.ch"
  12.  
  13. static CurInfo              //current active info object
  14. static initialized:=false   //memoedit initialized?
  15. static isTop:=false         //hit top for memoedit?
  16. static isBottom:=false      //...
  17. static needUp:=false        //command after memoedit
  18. static needDown:=false      //...
  19.  
  20. create class Info from Task
  21.   export:
  22.   var Wrap       // true            //true for info, false for report view
  23.   var FName      // ""              //temp file name if Printed==true
  24.   var CanPrint   // true            //allow print command
  25.   var CanEdit    // false           //allow editting of ::Buff
  26.   var RecNo      // 0               //abstract variable for HelpField()
  27.   var CanErase   // false           //do not erase file (FName)
  28.   var Printed    // false           //look for terminating object
  29.   var SeeTop     // true            //need for child class FInfo (smart reading from file)
  30.   var SeeBottom  // true            //need for child class FInfo (smart reading from file)
  31.   var TextRow    // 1               //current text row
  32.   var TextMax    // 0               //max rows in text
  33.   var Buff       // ""              //text buffer
  34.   method New=InfoNew             //o:New()
  35.   method Init=InfoInit           //o:Init(Name,R,C,Rs,Cs,Clr,Shadow)
  36.   method GoodInit=InfoGoodInit   //o:GoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow)
  37.   method Print=InfoPrint         //o:Print()
  38.   method VPaint=InfoVPaint       //o:VPaint()
  39.   method VProcess=InfoVProcess   //o:VProcess()
  40.   endclass
  41.  
  42.  
  43. //*****************************************************************************
  44. // Info:New() --> self
  45. // initialize new object
  46. //
  47. constructor InfoNew()
  48.   ::Color:= m->Color:View   //override
  49.   ::Wrap:= true
  50.   ::FName:= ""
  51.   ::CanPrint:= true
  52.   ::CanEdit:= false
  53.   ::RecNo:=0
  54.   ::CanErase:= false
  55.   ::Printed:= false
  56.   ::SeeTop:= true
  57.   ::SeeBottom:= true
  58.   ::TextRow:= 1
  59.   ::TextMax:= 0
  60.   ::Buff:= ""
  61.   ::DoneBlock:= {|o|DoDone(o)}
  62.   return(self)
  63.  
  64.  
  65. //-----------------------------------------------------------------------------
  66. // Info::DoDone() --> true/false
  67. // selectable erasing report file
  68. //
  69. static function DoDone(Info)
  70.   local Ch
  71.   returnif !Info:Printed  with true
  72.   returnif !Info:CanErase with true
  73.   Info:Top(false)
  74.   Ch:=Alert(ResTxt(091)+" "+Info:FName+";"+ResTxt(092),ResTxt(132))
  75.   do case
  76.     case Ch==1
  77.       FErase(Info:FName)
  78.       return(true)
  79.     case Ch==2
  80.       return(true)
  81.     otherwise
  82.       return(false)
  83.   endcase
  84.   return(false)   //dummy line
  85.  
  86.  
  87. //-----------------------------------------------------------------------------
  88. // GetReportName() --> cFileName
  89. // look for existing files and return new (unique) report file name
  90. //
  91. function GetNewRepName()  //file name can be: SysRNNNN.txt, NNNN is number from 0001 to 9999
  92.   local a:={}             //array of numbers NNNN of currently existed files
  93.   local i:=1              //will be new number NNNN
  94.   AEval(Directory(cRptFile+"*.txt"),{|e|AAdd(a,Val(SubStr(e[1],5,4)))})
  95.   i:=AScan(ASort(a),{|e|e<>i++})
  96.   fill empty i with Len(a)+1
  97.   return(cRptFile+PadL(NTrim(i),4,"0")+".txt")
  98.  
  99.  
  100. //*****************************************************************************
  101. // Info:Init(Name,R,C,Rs,Cs,Clr,Shadow) --> true
  102. // initialize the object
  103. //
  104. method function InfoInit(Name,R,C,Rs,Cs,Clr,Shadow)
  105.   ::super(Task):Init(Name,R,C,Rs,Cs,Clr,Shadow)
  106.   return(EndInit(self))
  107.  
  108.  
  109. //*****************************************************************************
  110. // Info:GoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow) --> true
  111. // initialize the object
  112. //
  113. method function InfoGoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow)
  114.   ::super(Task):GoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow)
  115.   return(EndInit(self))
  116.  
  117.  
  118. //*****************************************************************************
  119. // Info::EndInit() --> true
  120. // initialize Info extension instvar
  121. //
  122. static function EndInit(Info)
  123.   Info:MinRows:=3
  124.   return(true)
  125.  
  126.  
  127. //*****************************************************************************
  128. // Info:Print() --> true/false
  129. // printing all info buffer
  130. //
  131. method function InfoPrint()
  132.   local FName,Handle
  133.   if !::Printed
  134.     FName:=GetNewRepName()
  135.     Handle:=FCreate(FName)
  136.     if Handle==-1; Alert(ResTxt(090)); return(false); endif
  137.     FWrite(Handle,::Buff)
  138.     FClose(Handle)
  139.     ::FName:=FName
  140.     ::Printed:=true
  141.   endif
  142.   PrintFile(FName)
  143.   return(true)
  144.  
  145.  
  146. //*****************************************************************************
  147. // Info:VPaint() --> true
  148. // virtual paint
  149. //
  150. method function InfoVPaint()
  151.   local Color:=::Color
  152.   ::TextMax:=MLCount(::Buff,if(::Wrap,::ColSize,250))
  153.   if m->tColor==3
  154.     Color:=ListAsArray(Color)
  155.     Color:=GetFore(Color[nUnSelect])+"/"+GetBack(Color[nNormal])
  156.   endif
  157.   SetColor(Color)
  158.   MemoEdit(::Buff, ::Row+1,::Col+1, ::Row+::RowSize,::Col+::ColSize, false,false,if(::Wrap,::ColSize,250),,::TextRow)
  159.   ShowTime()
  160.   return(true)
  161.  
  162.  
  163. //*****************************************************************************
  164. // Info:VProcess() --> true
  165. // virtual process
  166. //
  167. method function InfoVProcess()
  168.   local OldKey,OldWFK
  169.   local Color:=::Color
  170.   local OldInfo:=CurInfo          //save old info object
  171.   CurInfo:=self                   //set new info object (need for TextViewFnc)
  172.   if m->tColor==3
  173.     Color:=ListAsArray(Color)
  174.     Color:=GetFore(Color[nUnSelect])+"/"+GetBack(Color[nNormal])
  175.   endif
  176.   SetColor(Color)
  177.   if ::CanEdit
  178.     SaveDOut(ResTxt(148))
  179.   else
  180.     SaveDOut(ResTxt(147)+if(::CanPrint,","+ResTxt(136),""))
  181.   endif
  182.   SaveHelpIdx({15,1})
  183.   SetPos(::Row+Min(::RowSize,::TextMax),Col())  //cursor in memoedit will be appear here
  184.   SetLastKey(0)
  185.   initialized:=false
  186.   isTop:=false
  187.   isBottom:=false
  188.   needUp:=false
  189.   needDown:=false
  190.   if ::TextRow<1; ::TextRow:=1; endif
  191.   ::TextRow+=::RowSize-1
  192.   if ::CanEdit; SetCursor(if(Set(_SET_INSERT),SC_INSERT,SC_NORMAL)); endif
  193.   DisableHelp()
  194.   OldWFK:=SetKey(nWaitForKey,{||WaitKey()})
  195.   if( ::CanEdit, OldKey:=SetKey(nSwapTask,{||StuffKey(K_CTRL_W)}), )
  196.   begin sequence
  197.   ::Buff:=MemoEdit(::Buff, ::Row+1,::Col+1, ::Row+::RowSize,::Col+::ColSize, ::CanEdit,if(::CanEdit,"MemoEditFnc","TextViewFnc"),if(::Wrap,::ColSize,250),4, ::TextRow,0,::RowSize-1)
  198.   end sequence
  199.   if( ::CanEdit, SetKey(nSwapTask,OldKey), )
  200.   SetKey(nWaitForKey,OldWFK)
  201.   EnableHelp()
  202.   ::TextRow-=Row()-::Row-1
  203.   SetCursor(SC_NONE)
  204.   RestHelpIdx()
  205.   CurInfo:=OldInfo
  206.   RestDOut()
  207.   return(true)
  208.  
  209. static procedure WaitKey()
  210.   while NextKey()==0; ShowTime(); endwhile
  211.   return
  212.  
  213.  
  214. //*****************************************************************************
  215. // TextViewFnc() --> nMemoAction
  216. // memo user function
  217. //
  218. function TextViewFnc(nMode,nRow,nCol)
  219.   local Ch
  220.   CurInfo:TextRow:=nRow
  221.   breakif LastKey()==nSwapTask or LastKey()==K_CTRL_RET
  222.   if nMode==ME_INIT
  223.     returnif initialized with 0
  224.     initialized:=true
  225.     SetCursor(SC_SPECIAL1)
  226.     return ME_TOGGLESCROLL
  227.   endif
  228.   Ch:=LastKey()
  229.   do case
  230.     case Ch==nWaitForKey; while NextKey()==0; ShowTime(); endwhile
  231.     case Upper(Chr(Ch))=="P"
  232.       if CurInfo:CanPrint
  233.         InKey()
  234.         if Alert(ResTxt(093),ResTxt(123))==1; CurInfo:Print(); endif
  235.       endif
  236.     case Ch==K_UP;        if isTop and !CurInfo:SeeTop; needUp:=true; break; endif
  237.     case Ch==K_DOWN;      if isBottom and !CurInfo:SeeBottom; needDown:=true; break; endif
  238.     case Ch==K_PGUP;      if isTop and !CurInfo:SeeTop; needUp:=true; break; endif
  239.     case Ch==K_PGDN;      if isBottom and !CurInfo:SeeBottom; needDown:=true; break; endif
  240.     case Ch==K_CTRL_PGUP; if !CurInfo:SeeTop; needUp:=true; break; endif
  241.     case Ch==K_CTRL_PGDN; if !CurInfo:SeeBottom; needDown:=true; break; endif
  242.   endcase
  243.   isTop:=(nRow==1)
  244.   isBottom:=(nRow==CurInfo:TextMax)
  245.   needUp:=false
  246.   needDown:=false
  247.   if( Ch<>K_CTRL_W and Ch<>K_ESC and Ch<>K_CTRL_RET and NextKey()==0, StuffKey(nWaitForKey), )
  248.   return(0)
  249.  
  250. //------------------------------------------------------- eof (c)JHK ----------
  251.  
  252.